package com.itheima.bos.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.transit.SignInfoRepository;
import com.itheima.bos.dao.transit.TransitInfoRepository;
import com.itheima.bos.domain.transit.SignInfo;
import com.itheima.bos.domain.transit.TransitInfo;
import com.itheima.bos.index.WayBillIndexRepository;
import com.itheima.bos.service.transit.SignInfoService;

@Service
@Transactional
public class SignInfoServiceImpl implements SignInfoService {
	
	@Autowired
	private SignInfoRepository signInfoRepository;
	
	@Autowired
	private TransitInfoRepository transitInfoRepository;
	
	@Autowired
	private WayBillIndexRepository wayBillIndexRepository;

	@Override
	public void save(String transitInfoId, SignInfo signInfo) {
		
		signInfoRepository.save(signInfo);
		
		TransitInfo transitInfo = transitInfoRepository.findOne(Integer.parseInt(transitInfoId));
		
		transitInfo.setSignInfo(signInfo);
		
		if (signInfo.getSignType().equals("正常")) {
			transitInfo.setStatus("正常签收");
			transitInfo.getWayBill().setSignStatus(3);
			//同步索引库
			wayBillIndexRepository.save(transitInfo.getWayBill());
		}else{
			transitInfo.setStatus("异常");
			transitInfo.getWayBill().setSignStatus(4);
			//同步索引库
			wayBillIndexRepository.save(transitInfo.getWayBill());
		}
		
	}

}
